<?php

namespace App\Console\Commands;

use App\Models\Config;
use App\Services\SmsService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class ClearDbData extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'clear_db_data';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '清空数据';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        dd('exit');
        $tableMaps = Config::$relationClassMaps;
        $tables = collect($tableMaps)->keys()->all();
        foreach($tables as $table) {
            echo "清空表{$table}\r\n";
            $sql = 'TRUNCATE TABLE ' . $table . ";";
            $sql .= "ALTER TABLE {$table} AUTO_INCREMENT = 1;";
            # 不轻易操作，需要再打开
            // DB::unprepared($sql);
        }
    }
}
